<template>
  <el-main>
   <el-table
      v-loading="loading"
      :data="tableData0_0"
      ref="tableData0_0"
      style="width:100%"
      :span-method="objectSpanMethod"
      border
      class="table0_0"
    >
      <el-table-column
        prop="itemTypeText"
        label="统计分类"
        width="200"
        header-align="center"
        align="center"
        fixed
      >
      </el-table-column>
      <el-table-column
        prop="itemDisplayText"
        label="分类"
        width="300"
        header-align="center"
        align="left"
        fixed
      >
      </el-table-column>
      <el-table-column
        prop="itemDisplayCode"
        label="代码"
        width="150"
        header-align="center"
        align="center"
        fixed
      >
      </el-table-column>
      <el-table-column label="合计" header-align="center" align="center">
        <el-table-column
          label="幅"
          width="120"
          prop="receiveNum_total"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="MB"
          width="120"
          prop="dataSize_total"
          header-align="center"
          align="center"
        >
        </el-table-column>
      </el-table-column>
      <el-table-column label="1:500" header-align="center" align="center">
        <el-table-column
          label="幅"
          width="120"
          prop="receiveNum_500"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="MB"
          width="120"
          prop="dataSize_500"
          header-align="center"
          align="center"
        >
        </el-table-column>
      </el-table-column>
      <el-table-column label="1:1000" header-align="center" align="center">
        <el-table-column
          label="幅"
          width="120"
          prop="receiveNum_1000"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="MB"
          width="120"
          prop="dataSize_1000"
          header-align="center"
          align="center"
        >
        </el-table-column>
      </el-table-column>
      <el-table-column label="1:2000" header-align="center" align="center">
        <el-table-column
          label="幅"
          width="120"
          prop="receiveNum_2000"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="MB"
          width="120"
          prop="dataSize_2000"
          header-align="center"
          align="center"
        >
        </el-table-column>
      </el-table-column>
      <el-table-column label="1:5000" header-align="center" align="center">
        <el-table-column
          label="幅"
          width="120"
          prop="receiveNum_5000"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="MB"
          width="120"
          prop="dataSize_5000"
          header-align="center"
          align="center"
        >
        </el-table-column>
      </el-table-column>
      <el-table-column label="1:1万" header-align="center" align="center">
        <el-table-column
          label="幅"
          width="120"
          prop="receiveNum_10000"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="MB"
          width="120"
          prop="dataSize_10000"
          header-align="center"
          align="center"
        >
        </el-table-column>
      </el-table-column>
       <el-table-column label="1:2.5万" header-align="center" align="center">
        <el-table-column
          label="幅"
          width="120"
          prop="receiveNum_25000"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="MB"
          width="120"
          prop="dataSize_25000"
          header-align="center"
          align="center"
        >
        </el-table-column>
      </el-table-column>
       <el-table-column label="1:5万" header-align="center" align="center">
        <el-table-column
          label="幅"
          width="120"
          prop="receiveNum_50000"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="MB"
          width="120"
          prop="dataSize_50000"
          header-align="center"
          align="center"
        >
        </el-table-column>
      </el-table-column>
       <el-table-column label="1:10万" header-align="center" align="center">
        <el-table-column
          label="幅"
          width="120"
          prop="receiveNum_100000"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="MB"
          width="120"
          prop="dataSize_100000"
          header-align="center"
          align="center"
        >
        </el-table-column>
      </el-table-column>
       <el-table-column label="1:25万" header-align="center" align="center">
        <el-table-column
          label="幅"
          width="120"
          prop="receiveNum_250000"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="MB"
          width="120"
          prop="dataSize_250000"
          header-align="center"
          align="center"
        >
        </el-table-column>
      </el-table-column>
       <el-table-column label="1:50万" header-align="center" align="center">
        <el-table-column
          label="幅"
          width="120"
          prop="receiveNum_500000"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="MB"
          width="120"
          prop="dataSize_500000"
          header-align="center"
          align="center"
        >
        </el-table-column>
      </el-table-column>
       <el-table-column label="1:100万" header-align="center" align="center">
        <el-table-column
          label="幅"
          width="120"
          prop="receiveNum_1000000"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="MB"
          width="120"
          prop="dataSize_1000000"
          header-align="center"
          align="center"
        >
        </el-table-column>
      </el-table-column>
       <el-table-column label="其他" header-align="center" align="center">
        <el-table-column
          label="幅"
          width="120"
          prop="receiveNum_other"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="MB"
          width="120"
          prop="dataSize_other"
          header-align="center"
          align="center"
        >
        </el-table-column>
      </el-table-column>
    </el-table>
  </el-main>
</template>

<script>
import { get4DReport} from "@/api/report/basic";

export default {
  name: "table0_0",
  data() {
    return {
    spanArr: [],
      spanArr1: [],
      pos:0,
      tableData0_0: [],
      //用于存储总计统计信息
      tableData0_0_total: [],
      //用于存储单位类型统计信息
      tableData0_0_unittype: [],
      //用于存储是否有偿统计信息
      tableData0_0_ispaid: [],
      loading: false,
      formData:{
        unit_leader: "",
        statistics_leader: "",
        informant: "",
        iphone: "",
        submit_date: ""
      }
    };
  },
  mounted: function () {
    // 组件创建完后获取数据，
    // 此时 data 已经被 observed 了
    let date = new Date(); 
    this.formData.submit_date = date.getFullYear()+"-"+(date.getMonth()+1)+'-'+date.getDate()
    this.$emit("reportSearch","");
  },
  methods:{
      merageInit() {
        //初始化合并行的数组
        this.spanArr = [];
        this.pos = 0;
      },
      getSpanArr(data) {
      this.merageInit();
      for (var i = 0; i < data.length; i++) {
        if (i === 0) {
          this.spanArr.push(1);
          this.pos = 0;
        } else {
          // 判断当前元素与上一个元素是否相同
          if (data[i].itemTypeText === data[i - 1].itemTypeText) {
            this.spanArr[this.pos] += 1;
            this.spanArr.push(0);
          } else {
            this.spanArr.push(1);
            this.pos = i;
          }
        }
      }
    },
    objectSpanMethod({ rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        const _row = this.spanArr[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col
        }
      }
    },
    getReportData(queryParam) {
      this.loading = true;
      var condition = {};
      condition.dataTypes = "数字正射影像（DOM）,DOM";
      if(queryParam){
          console.log(queryParam);
          condition.beginTime = queryParam.beginTime;
          condition.endTime = queryParam.endTime;
          get4DReport(condition).then(response => {
                 this.tableData0_0 = response.rows;
                 this.total = response.total;
                 this.getSpanArr(this.tableData0_0);
                 this.loading = false;
          });
      }else{
        this.tableData0_0 = [];
        this.loading = false;
      }
    },
    export2Excel(name) {
        const tHeader1 = ["分类",  "代码", "幅","MB","幅","MB","幅","MB","幅","MB","幅","MB","幅","MB","幅","MB","幅","MB","幅","MB","幅","MB","幅","MB","幅","MB","幅","MB"];
        var filterVal = []
        for(var i in this.tableData0_0[0]){
          if(i != "itemType" && i != "itemCodes" && i != "itemTypeText"){
            filterVal.push(i)
          }
        }
        console.log(filterVal)
       // common.export2Excel(name,tHeader,filterVal,this.tableData0_0)
        require.ensure([], () => {
          const { export_json_to_excel } = require("@/views/basic-report/common/Export2Excel");
          //const tHeader = theader;
          let tHeader = [name,'','','','','','','','','','','','','','','','','','','','','','','','','','','']
          const list = this.tableData0_0;
          //从上到下依次填充导出数据
          const data = [];

          data.push(['填报单位：甘肃省基础地理信息中心','','','','','','','','','','','','','','','','','','','','','','','','','','时期:',''])
          data.push(['分类','代码','合计','','1:500','','1:1000','','1:2000','','1:5000','','1:1万','','1:2.5万','','1:5万','','1:10万','','1:25万','','1:50万','','1:100万','','其他','']);
          data.push(tHeader1);
          data.push(['甲','乙','1','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27'])
          
          this.tableData0_0_total = [];
          this.tableData0_0_total.push(this.tableData0_0[0]);
          const data_total = this.formatJson(filterVal, this.tableData0_0_total);

          data.push(data_total[0]);

          data.push(['一.按成果领用单位类型统计','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-'])
          
          
          
          for(var i=1;i<this.tableData0_0.length-2;i++){
              const data_unittype = this.formatJson(filterVal, [this.tableData0_0[i]]);
              data.push(data_unittype[0]);
          }
         // data = data.concat(data_unittype);
          

          data.push(['二.按成果使用方式统计','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-']);

          for(var i=this.tableData0_0.length-2;i<this.tableData0_0.length;i++){
              const data_ispaid = this.formatJson(filterVal, [this.tableData0_0[i]]);
              data.push(data_ispaid[0]);
          }
          
          data.push(['','','','','','','','','','','','','','','','','','','','','','','','','','','',''])
          data.push(['单位负责人：',this.formData.unit_leader,'','','','','','','','','','','','','','','','','','','','','','','','','',''])
          data.push(['统计负责人：',this.formData.statistics_leader,'','','','','','','','','','','','','','','','','','','','','','','','','',''])
          data.push(['填报人：',this.formData.informant,'','','','','','','','','','','','','','','','','','','','','','','','','',''])
          data.push(['联系电话：',this.formData.iphone,'','','','','','','','','','','','','','','','','','','','','','','','','',''])
          data.push(['报出日期：',this.formData.submit_date,'','','','','','','','','','','','','','','','','','','','','','','','','',''])
          data.push(['','','','','','','','','','','','','','','','','','','','','','','','','','','',''])
          data.push(['说明：','','','','','','','','','','','','','','','','','','','','','','','','','','',''])
          data.push(['1.填报单位：省级和计划单列市自然资源主管部门所属测绘成果档案部门，国家基础地理信息中心。','','','','','','','','','','','','','','','','','','','','','','','','','','',''])
          data.push(['2.报告期别：年报，季报。','','','','','','','','','','','','','','','','','','','','','','','','','','',''])
          data.push(['3.表中的计量单位“幅”、“MB”统计累计提供的数据量。','','','','','','','','','','','','','','','','','','','','','','','','','','',''])
          data.push(['4.逻辑关系：1-3+5+7+9+11+13+15+17+19+21+23+25；2-4+6+8+10+12+！4+16+18+20+22+24+26；01-02+03+04+07+08+09-10+11；04≥05+06','','','','','','','','','','','','','','','','','','','','','','','','','','',''])
          export_json_to_excel(tHeader, data, name);
        });
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j =>{
        console.log(j);
        if((j.indexOf("dataSize_")==0)||(j.indexOf("coverageRange_")==0)){
          return Math.round(v[j]);
        }else{
          return v[j];
        }
        }));
    },
  }
};
</script>
<style scoped>
.el-row{
  margin:12px 0;
}
</style>
